//
//  XuanTaiData.m
//  BigTyre
//
//  Created by 💋索少杰 on 2017/3/21.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "XuanTaiData.h"
#import <AFNetworking.h>
#import "SelectTyreModel.h"
#import "SelectTyreCollectionModel.h"


#define Url @"http://lscy4.caeac.com.cn/api/product_fenlei.php?appkey=1138"
//静态标示符
static XuanTaiData*data=nil;
@implementation XuanTaiData
//单利
+(instancetype)shardData{
    static dispatch_once_t oneKen;
    _dispatch_once(&oneKen, ^{
        
        data=[[XuanTaiData alloc]init];
    });
    return data;
}
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    if (!data) {
        data = [super allocWithZone:zone];
    }
    return data;
}
-(id)copy{
    return self;
}
-(id)mutableCopy{
    return self;
}
//数据请求
-(void)getUrlRequest {
    
    AFHTTPSessionManager*manager=[AFHTTPSessionManager manager];
    manager.responseSerializer=[AFJSONResponseSerializer serializer];
    
    [manager GET:Url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        arrData=[[NSMutableArray alloc]init];
        
        NSArray *arr = (NSArray *)responseObject;
        for (NSDictionary *dic in arr) {
            SelectTyreModel*model=[[SelectTyreModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [arrData addObject:model];
            
        }
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"suo" object:arrData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"111");
    }];
}

- (void)getUrlRequestCollection:(NSString *)url seccess:(Seccessfaul)seccess {
    AFHTTPSessionManager*manager=[AFHTTPSessionManager manager];
    manager.responseSerializer=[AFJSONResponseSerializer serializer];
    
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        collectionArrData=[[NSMutableArray alloc]init];
        SelectTyreCollectionModel*model=[[SelectTyreCollectionModel alloc]init];
        [model setValuesForKeysWithDictionary:(NSDictionary*)responseObject];
        
        for (NSDictionary*dic in model.product) {
            SelectTyreCollectionModel_product*model_product=[[SelectTyreCollectionModel_product alloc]init];
            [model_product setValuesForKeysWithDictionary:dic];
            [collectionArrData addObject:model_product];
            
            
        }
        
        //[[NSNotificationCenter defaultCenter]postNotificationName:@"suo1" object:collectionArrData];
        if (seccess) {
            seccess(collectionArrData);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"111");
        
    }];
}


@end
